package com.bdqn.service.impl;

import com.bdqn.dao.UserDao;
import com.bdqn.dao.impl.UserDaoImpl;
import com.bdqn.factory.UserDaoFactory;
import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 崔书健
 * @date 2024/7/10
 */
@Service("userService")
public class UserServiceImpl implements UserService {

//    // 示例1（直接new创建实例，高耦合性）
//    private UserDao userDao = new UserDaoImpl();
    // 示例2(简单工厂模式)
//    private UserDao userDao = UserDaoFactory.getInstance();
    // 示例14(依赖倒置)
    @Autowired
//    @Qualifier("userDao")
//    @Resource(name = "userDao")
//    @Resource(type = UserDaoImpl.class)
    private UserDao userDao;

    public UserServiceImpl() {
    }

    public UserServiceImpl(UserDaoImpl userDao) {
    }

    /**
     * dao属性的setter访问器，会被Spring调用，实现设置注入
     * @param userDao
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     * 保存用户信息
     *
     * @param user
     */
    @Override
    public void save(User user) {
        // 调用UserDao的方法保存用户信息
        userDao.save(user);
    }
}
